<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("编辑车辆")}</title>
<link href="/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/jquery.js"></script>
<script type="text/javascript" src="/resources/js/base/dialog.js"></script>
<script type="text/javascript" src="/resources/js/base/request.js"></script>
<script type="text/javascript" src="/resources/js/base/global.js"></script>
<script type="text/javascript" src="/resources/js/reference/jquery.validate.js"></script>
<script type="text/javascript" src="/resources/plugin/datePicker/WdatePicker.js"></script>
<link href="/resources/css/mmGrid.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/mmGrid.js"></script>
<script src="/resources/js/base/file.js"></script>
<script type="text/javascript">
function editQty(t,e){
	extractNumber(t,0,false,e);
}
$().ready(function() {
	var $inputForm = $("#inputForm");
	var $addElock = $("#addElock");
	var $deleteElock = $("a.deleteElock");

	// 表单验证
	$inputForm.validate({
		rules: {
			carNumber: {
				required: true
			},
			carType: {
				required:true
			},
			saleOrgId: {
				required:true
			},
			berth: {
				required:true
			},
		}
	});
	
	//打开选择锁界面
	var types = {'1':'${message("160002")}','2':'${message("160003")}','3':'${message("160004")}','4':'${message("160005")}','5':'${message("160006")}'};
	$addElock.click(function(){
        $addElock.bindQueryBtn({
            type:'elock',
            bindClick:false,
            title:'${message("查询锁")}',
    		url:'/elock/select_list.jhtml?multi=2',
            callback:function(rows){
                if(rows.length>0){
                    for (var i = 0; i < rows.length;i++) {
                    	var $elock_id = $("input.elockId[value='"+rows[i].id+"']");
    					if($elock_id.length>0){
    						$.message_alert('锁【'+rows[i].elock_name+'】已添加');
    						return false;
    					}
                    }
                    for (var i = 0; i < rows.length;i++) {
						var row = rows[i];
						row.elockNum=rows[i].elock_num;
						row.elockName=rows[i].elock_name;
						row.type=rows[i].type_value;
						row.model=rows[i].model_value;
						row.berth=1;
						$tmGrid.addRow(row,null,1);
					}
                }
            }
        }); 
    })
	 
	var elockInItemIndex = 0;
	[#if elockCars!=null]
		var elockCars = ${elockCars};
	[#else]
		var elockCars = {};
	[/#if]
 	var cols = [
		{ title:'${message("舱位")}', name:'berth' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			val==''?1:val;
			var html='<div class="nums-input ov">'+
        	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
        	'<input type="text"  class="t requireds"  name="berth" value="'+val+'" minData="1" maxData="4" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
        	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
    	'</div>';
			return html;
		}},
    	{ title:'${message("锁编号")}', name:'elockNum' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			var	html = '<input type="hidden" name="elockId" class="elockId elockId_'+item.id+'" value="'+item.id+'" />'+val;
			return html;}
		},
    	{ title:'${message("锁名称")}', name:'elockName' ,align:'center', width:110},
    	{ title:'${message("锁类型")}', name:'type_value' ,align:'center' },
		{ title:'${message("锁型号")}', name:'model_value' ,align:'center' },
    	{ title:'${message("安装位置")}', name:'position' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
				val==undefined?"":val;
				var	html = '<select name="position" class="text position" >'+
				'<option value ="上" '+(val=="上"?"selected=selected":"")+'>上</option>'+
				'<option value ="下" '+(val=="下"?"selected=selected":"")+'>下</option>'+
				'</select>';
				return html;
			}
    	},
//     	{ title:'${message("序号")}', name:'seq' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
    			
//     		var html='<div class="nums-input ov">'+
//         	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
//         	'<input type="text"  class="t seq"  name="seq" value="'+val+'" minData="0" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
//         	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
//     	'</div>';
// 			return html;
//     	}},
		{ title:'${message("操作")}', align:'center', width:60, renderer:function(val,item){
			elockInItemIndex++;
		return '<a href="javascript:;" class="deleteElock btn-delete">删除</a>';
		}},
	];
	var $tmGrid=$('#table-elock').mmGrid({
		fullWidthRows:true,
		height:'auto',
        cols: cols,
        items:elockCars,
        autoLoad: true,
    });

	// 删除锁
    $deleteElock.live("click", function() {
        var index = $(this).closest("tr").index();
		$.message_confirm('您确定要删除吗？',function(){
			$tmGrid.removeRow(index);
		})
    });

	$("form").bindAttribute({
		isConfirm:true,
	    callback: function(resultMsg){
	        $.message_timer(resultMsg.type,resultMsg.content,1000,function(){
				location.reload(true);
			});
	    }
	 });
	
	//查询机构
	$("#selectSaleOrg").bindQueryBtn({
		type:'saleOrg',
		title:'${message("查询机构")}',
		url:'/saleOrg/select_saleOrg.jhtml'
	});
	
// 	$.validator.addClassRules({
// 		requireds: {
// 			required: true
// 		}
// 	});
	
});	
</script>
</head>
<body>
	<div class="pathh">
		&nbsp;${message("编辑车辆")}
	</div>
	<form id="inputForm" action="update.jhtml" method="post" type="ajax" validate-type="validate">
		<input type="hidden" name="id" value="${car.id}" />
		<div class="tabContent">
			<table class="input input-edit">
			<tr>
				<th>
					<span class="requiredField">*</span>${message("车牌号")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" value = "${car.carNumber}" name="carNumber" class="text " maxlength="20"   btn-fun="clear"/></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("车型")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" name="carType"  value = "${car.carType}" class="text " maxlength="20"   btn-fun="clear"/></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("机构")}:
				</th>
				<td>
					<span class="search" style="position:relative">
					<input type="hidden" name="saleOrgId" class="text saleOrgId" btn-fun="clear" [#if saleOrg??]value="${saleOrg.id}"[/#if]/>
					<input type="text" name="saleOrgName" class="text saleOrgName" maxlength="200" onkeyup="clearSelect(this)" value="[#if saleOrg??]${saleOrg.name}[/#if]" readOnly/>
					<input type="button" class="iconSearch" value="" id="selectSaleOrg">
					</span>
				</td>
				<th>
					${message("备注")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" value="${car.remark}" name="remark" class="text " maxlength="20"   btn-fun="clear"/></span>
				</td>
				<!-- <tr class="partsShow border-L3">
				<th>
					${message("安装的锁")}:
				</th>
				<td colspan="7">
					<a href="javascript:;" id="addElock" class="button">${message("选择安装的锁")}</a>
				</td>
				</tr>
				<tr class="isSelectedTr border-L3">
					<th>
						&nbsp;
					</th>
					<td colspan="7">
						<div class="clearfix"></div>
						<table class="input  table-fixed" id="partsTable">
							<thead>
							<tr>
								<th>
									${message("锁编号")}
								</th>
								<th>
									${message("安装位置")}
								</th>
								<th style="width:70px">
									${message("操作")}
								</th>
							</tr>
							</thead>
							<tbody>
							[#list elockCars as elockCar]
								<tr>
									<td>
									<input type="hidden" name="elockId" class="elockId" value="${elockCar.elockId }"  />${elockCar.elockNum}</td>
									<td>
										<select name="position" class="text" style="width:100px">
											<option value ="1上" [#if elockCar.position=="1上"]selected[/#if]>1上</option>
											<option value ="1下" [#if elockCar.position=="1下"]selected[/#if]>1下</option>
											<option value ="2上" [#if elockCar.position=="2上"]selected[/#if]>2上</option>
											<option value ="2下" [#if elockCar.position=="2下"]selected[/#if]>2下</option>
										</select>
									</td>
									<td><a href="javascript:;" class="deleteElock btn-delete">${message("1002")}</a></td>
								</tr>
							[/#list]
							<tr id="elockTr">
							</tr>
							</tbody>
						</table>
					</td>
				</tr> -->
			</tr>
			<tr class="partsShow border-L3">
				<th>
					${message("安装的锁")}:
				</th>
				<td colspan="7">
					<a href="javascript:;" id="addElock" class="button">${message("选择安装的锁")}</a>
				</td>
				</tr>
				<tr class="border-L3">
            	<td colspan="8">
            		<div>
						<table id="table-elock"></table>
					</div>
            	</td>
            	</tr>
		</table>
		</div>
		<div class="fixed-top">
			<a href="add.jhtml" class="iconButton" id="addButton">
				<span class="addIcon">&nbsp;</span>${message("1001")}
			</a>
			<input type="submit" id="submit_button" class="button sureButton" value="${message("1013")}" />
			<input type="button" onclick="location.reload(true);" class="button resetButton ml15" value="${message("刷新")}">
		</div>
	</form>
</body>
</html>